package com.besovideo.mpu;

import org.opencv.facetrackmatch.facedetect.FaceTrackTool;

import com.smarteye.mpu.MPUGlobal;
import com.smarteye.mpu.MainService.Connection;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class FaceComparisonDialog extends Dialog {
	Context context;
	FaceTrackTool faceTrackTool;
	int lay;
	boolean isComparison;
	Connection mConnection;
	RadioGroup m_RadioGroup;
	RadioButton m_RadioButtonFaceComparisonOpen;
	RadioButton m_RadioButtonFaceComparisonClose;

	public FaceComparisonDialog(Context context, FaceTrackTool faceTrackTool) {
		super(context, R.style.TransparentDialogHaveTitle);
		this.context = context;
		this.lay = R.layout.face_comparison;
		this.faceTrackTool = faceTrackTool;
		mConnection = ((MPUGlobal) ((MainActivity) context).getApplication())
				.getConnection();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(lay);

		m_RadioGroup = (RadioGroup) findViewById(R.id.radioGroupFaceComparison);
		m_RadioButtonFaceComparisonOpen = (RadioButton) findViewById(R.id.radioButtonFaceComparisonOpen);
		m_RadioButtonFaceComparisonClose = (RadioButton) findViewById(R.id.radioButtonFaceComparisonClose);

		SelectSet();
		m_RadioGroup
				.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

					@Override
					public void onCheckedChanged(RadioGroup group, int checkedId) {
						// TODO Auto-generated method stub
						MainActivity parent = (MainActivity) context;
						if (checkedId == m_RadioButtonFaceComparisonOpen
								.getId()) {
							parent.subConfigMenuListViewAdapter
									.setText(
											MainActivity.SubConfigMenuEnum.SUB_MENU_FACE_COMPARISON
													.value(),
											m_RadioButtonFaceComparisonOpen
													.getText().toString());
							faceTrackTool.setmComparison(true);
						} else {
							parent.subConfigMenuListViewAdapter
									.setText(
											MainActivity.SubConfigMenuEnum.SUB_MENU_FACE_COMPARISON
													.value(),
											m_RadioButtonFaceComparisonClose
													.getText().toString());
							faceTrackTool.setmComparison(false);
						}
						parent.subConfigMenuListViewAdapter
								.notifyDataSetChanged();
						dismiss();
					}
				});
	}

	private void SelectSet() {
		isComparison = faceTrackTool.ismComparison();
		if (isComparison) {
			m_RadioGroup.check(m_RadioButtonFaceComparisonOpen.getId());
		} else {
			m_RadioGroup.check(m_RadioButtonFaceComparisonClose.getId());
		}
	}
}
